package com.hrzyit.whistle.cases.presenter

import com.hrzyit.base.ext.execute
import com.hrzyit.base.presenter.BasePresenter
import com.hrzyit.base.rx.BaseObserver
import com.hrzyit.whistle.cases.data.bean.UploadInfo
import com.hrzyit.whistle.cases.presenter.view.RecordAudioView
import com.hrzyit.whistle.cases.service.IUploadService
import javax.inject.Inject

/**
 * 录音组件 Presenter
 * @author YangWei
 * @date 2019/4/13
 */
class RecordAudioPresenter @Inject constructor() : BasePresenter<RecordAudioView>() {

    @Inject
    lateinit var uploadService: IUploadService

    /**
     * 上传音频文件
     * @author YangWei
     * @date 2019/4/13
     * @param audioFilePath 本地音频文件路径
     */
    fun uploadRecordAudio(audioFilePath: String) {
        if (!checkNetWork()) {
            return
        }

        // 显示进度框
        mView.showLoading()

        uploadService.uploadRecordAudio(audioFilePath)
            .execute(object : BaseObserver<UploadInfo>(mView) {
                override fun onNext(t: UploadInfo) {
                    mView.onUploadRecordAudioResult(t)
                }

            }, lifecycleProvider)

    }
}